<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="../lib/layui/css/layui.css"/>
    <script type="text/javascript" src="../lib/layui/layui.all.js"></script>
    <script type="text/javascript" src="../lib/jquery-3.5.1.js"></script>
    <script type="text/javascript" src="../lib/common.js"></script>
</head>
<body>
    <div class="layui-container">
        <button type="button" class="layui-btn" onclick="sendRequest95()">请求95</button>
        <button type="button" class="layui-btn" onclick="sendRequest100()">请求100</button>
        <button type="button" class="layui-btn" onclick="loop()">loop</button>
        <input type="text" id="code" class="layui-input">
        <button type="button" class="layui-btn" onclick="loop2()">loop2</button>
        <button type="button" class="layui-btn" onclick="test1()">TEST1</button>
        <button type="button" class="layui-btn" onclick="test2()">TEST2</button>
        <button type="button" class="layui-btn" onclick="test3()">TEST3</button>
        <button type="button" class="layui-btn" onclick="test4('http://localhost:8076/leo-tool/test/downloadExcel')">Ajax下载文件</button>
    </div>
</body>
<script>
    function test4(url) {
        var xhr = new XMLHttpRequest();
        xhr.open('POST', url, true);
        xhr.setRequestHeader("Content-Type", "application/json")
        xhr.responseType = 'blob';
        xhr.onload = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                var blob = new Blob([xhr.response], { type: 'application/octet-stream' });
                //var responseHeader = xhr.getResponseHeader("Content-disposition"); 无法获取文件名
                var downloadUrl = URL.createObjectURL(blob);
                var a = document.createElement('a');
                a.href = downloadUrl;
                a.download = 'filename.xlsx';
                document.body.appendChild(a);
                a.click();
                document.body.removeChild(a);
            }
        };
        xhr.send('{"name":"李世明"}');
    }

    function test1() {
        ajaxGET({"name":"李世明"}, "https://robot.guiji.ai/video-matrices-server/tip/query?type=11", function (result) {
            console.log(result)
        })
    }
    function test2() {
        ajaxPost({"name":"李世明"}, "http://localhost:8054/v/test2", function (result) {
            console.log(result)
        })
    }
    function test33() {
        ajaxGET({"id":10}, "http://localhost:8090/student/get", function (result) {
            console.log(result)
        })
    }
    function test3() {
        ajaxPostJSON(JSON.stringify({"pageNum":1,"pageSize":10}), "http://localhost:8090/student/page", function (result) {
            console.log(result)
        })
    }
    function sendRequest95() {
        ajaxPost({"name":"李世明"}, "http://192.168.1.95:8034/menu/treeAll", function (result) {
            console.log(result)
        })
    }
    function sendRequest100() {
        ajaxPost({}, "http://192.168.1.100:7074/menu/treeAll", function (result) {
            console.log(result)
        })
    }

    function loop() {
        ajaxGET({}, "http://localhost:8054/doc/sayHi?name=xxx", function (result) {
            console.log(result)
        })
    }
    function loop2() {
        var code = $("#code").val();
        setInterval(function (){
            ajaxGET({}, "http://localhost:8080/wv/task/query?code=" + code, function (result) {
                console.log(result.data)
            })
        }, 1000)
    }
</script>
</html>
